CXX					= g++
CXXFLAGS		= -Wall -Wno-write-strings
CXXINC			= -Iinclude -I../Includes #-Itest/include
CXXLD				= $(CXX)
CXXLDFLAGS	=
RM					= rm

vpath %.h include:../include

EXE				= 
XENOEXE			= TestClient
SRCS			= $(wildcard *.cpp)
OBJS			= ${SRCS:.cpp=.opp}

# clear out all the suffixes
.SUFFIXES:
# list only those that we use
.SUFFIXES: .opp .cpp

# define a suffix rule for .cpp -> .opp
.cpp.opp:
	$(CXX) $(CXXINC) -o $@ -c $< $(CXXFLAGS) 

all:: $(XENOEXE)

###### Xenomai Config ######
### Note: to override the search path for the xeno-config script, use "make XENO=..."

###### USER SPACE BUILD (no change required normally) ######
ifeq ($(KERNELRELEASE),)
ifneq ($(XENOEXE),)

### Default Xenomai installation path
XENO ?= /usr/xenomai

XENOCONFIG=$(shell PATH=$(XENO):$(XENO)/bin:$(PATH) which xeno-config 2>/dev/null)

### Sanity check
ifeq ($(XENOCONFIG),)
xeno::
	@echo ">>> Invoke make like this: \"make XENO=/path/to/xeno-config\" <<<"
	@echo
else
xeno::$(XENOEXE) const int8_t getCar_num() ;
CXXFLAGS+=$(shell $(XENOCONFIG) --xeno-cflags) $(MY_CFLAGS)

CXXLDFLAGS=$(shell $(XENOCONFIG) --xeno-ldflags) $(MY_LDFLAGS) -lnative -lrtdk

# This includes the library path of given Xenomai into the binary to make live
# easier for beginners if Xenomai's libs are not in any default search path.
CXXLDFLAGS+=-Xlinker -rpath -Xlinker $(shell $(XENOCONFIG) --libdir)
endif
endif
endif
###### End Xenomai Config ######

xeno:: $(XENOEXE)

TestClient: main.opp Tester.opp ../Elevator.opp ../Supervisor.opp ../Comm_Manager.opp ../Double_Buffer.opp ../FloorRun_Manager.opp
	$(CXXLD) $(CXXLDFLAGS) -o $@ $^

#tests: test/test.opp test/testHeap.opp test/testMessage.opp Message.opp Heap.opp ElevatorCommon.opp
#	$(CXX) $(CXXINC) -o test/test $^ test/lib/libUnitTest++.a $(CXXFLAGS)

clean:
	-$(RM) -f $(EXE) $(OBJS) $(wildcard *.gch) $(wildcard test/*.opp) test/test EClient* TestClient*

Tester.opp : Tester.h

main.opp: Tester.h ../Elevator.h
